﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PowerBooking.RSE.Domain.Models;
using System.Threading.Tasks;
using System.Collections.Concurrent;
using System.Reflection;
using System.Data.Entity;
using PowerBooking.RSE.IRepository;
using System.Runtime.Caching;
using PowerBooking.RSE.Utility.Helpers;
using PowerBooking.RSE.Poco;

namespace PowerBooking.RSE.Domain.Factories
{
    /// <summary>
    /// 蜘蛛工厂
    /// </summary>
    public class SpiderFactory : Factory
    {
        public SpiderFactory(IUnitOfWork unitOfWork) : base(unitOfWork) { }

        /// <summary>
        /// 获取一只蜘蛛
        /// </summary>
        /// <param name="spiderID"></param>
        /// <returns></returns>
        public Spider QuerySpiderBySpiderID(long spiderID)
        {
            return new Spider().InitDomain(UnitOfWork.SpiderRepository.QuerySpiderBySpiderID(spiderID));
        }

        public Spider CreateSpider(string name, string url)
        {
            var spiderPoco = new SpiderPoco()
            {
                Name = name,
                Url = url
            };
            UnitOfWork.SpiderRepository.InsertSpider(spiderPoco);
            UnitOfWork.Save();
            return new Spider().InitDomain(spiderPoco);
        }
    }
}
